<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Methods Option 方法选项</title>
  <script src="../assets/js/vue.js"></script>
</head>

<body>
  <h1>Methods Option 方法选项</h1>
  <hr>
  <div id="app">
    {{a}}
    <p><button @click="add(2)">add</button></p>
    <p><btn @click.native="add(2)"></btn></p>
  </div>
  <button onclick="app.add(3)">外部ADD</button>
  <script type="text/javascript">
    var btn={
      template:`<button>组件ADD</button>`
    }
    var app = new Vue({
      el: '#app',
      data: {
        a: 1
      },
      components:{
        "btn":btn
      },
      methods:{
        add:function(num){
          console.log(event);
          if (num!='') {
            this.a+=num;
          }else{
            this.a++
          }
          
        }
      }
    })
  </script>
</body>

</html>